package com.java.config.exceptioin;

import com.java.config.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class GloabException {

    @ExceptionHandler(Exception.class)//当controller中抛出Exception，则捕获
    @ResponseBody//返回Json
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(YyghException.class)//自定义异常处理
    @ResponseBody
    public Result error(YyghException e){
        return Result.build(e.getCode(),e.getMessage());
    }
}
